package cn.jiyun.controller;

import cn.jiyun.pojo.DianPu;
import cn.jiyun.service.DianPuService;
import cn.jiyun.vo.ResultCommon;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("dianpu")
@CrossOrigin
public class DianPuController {

    @Autowired
    private DianPuService dianPuService;

    @RequestMapping("findAll")
    public ResultCommon findAll(@RequestParam(name = "pageNo",defaultValue = "1")Integer pageNo,
                                @RequestParam(name = "pageSize",defaultValue = "10")Integer pageSize,
                                @RequestBody DianPu dianPu){

        PageInfo<DianPu> pageInfo = dianPuService.findAll(pageNo,pageSize,dianPu);
        return ResultCommon.suceessData(pageInfo);
    }

    @PostMapping("add")
    public ResultCommon add(@RequestBody DianPu dianPu){
        Integer i = dianPuService.add(dianPu);
        if (i>0){
            return ResultCommon.suceess();
        }else {
            return ResultCommon.error("添加失败");
        }
    }

    @RequestMapping("delete")
    public void delete(Integer id){
        dianPuService.delete(id);
    }
}
